package sns.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import sns.bean.Mblog;
import sns.bean.User;
import sns.service.MblogService;
import sns.service.RelationService;
import sns.service.UserService;
import sns.util.HotUser;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GoToLoginAction extends ActionSupport {

	// injection
	private UserService userService;
	private MblogService mblogService;
	private RelationService relationService;

	// return value
	private List<HotUser> hotUsers;
	private List<User> newUsers;
	private List<Mblog> recentBlogs;
	private Long infoId=(long) 0; //1为注册成功直接跳转到登录界面 2为登录失败

	@Transactional
	public String execute() {
		System.out.println("infoId   "+ infoId);
		// Get top 6 hottest users to show on the login page
		List<User> hotUsersTmp = userService.getHotUsers(6);
		hotUsers = new ArrayList<HotUser>(hotUsersTmp.size());
		for(int i=0; i<hotUsersTmp.size(); i++){
			hotUsers.add(i, new HotUser(hotUsersTmp.get(i),relationService.getFollowerNum(hotUsersTmp.get(i))));
		}
		// Get top 10 recent added users
		newUsers = userService.getNewUsers(10);
		// Get top 3 recent published blogs
		recentBlogs = mblogService.getAllMblogs(3);

		// System.out.println("I am for the test in login "+ newUsers.get(0));
		return Action.SUCCESS;
	}

	public List<HotUser> getHotUsers() {

		return hotUsers;
	}

	public void setRelationService(RelationService relationService) {
		this.relationService = relationService;
	}

	public List<User> getNewUsers() {

		return newUsers;
	}

	public List<Mblog> getRecentBlogs() {

		return recentBlogs;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void setMblogService(MblogService mblogService) {
		this.mblogService = mblogService;
	}

	public void setInfoId(Long infoId) {
		this.infoId = infoId;
	}

	public Long getInfoId() {
		return infoId;
	}
}
